﻿namespace CoHubServerCore.Configurator;

public class Path
{
    private readonly Config _config;

    public string ConfigDirectory => _config.ConfigDirectory;

    public string ConfigPath => _config.ConfigPath;

    public string RootDirectory => _config.Core.Directory;

    public string DatabaseDirectory => System.IO.Path.Combine(RootDirectory, _config.DataBase.Directory);

    public string DatabasePath => System.IO.Path.Combine(DatabaseDirectory, _config.DataBase.Name);

    public string FtpDirectory => System.IO.Path.Combine(RootDirectory, _config.Ftp.Directory);
    
    private void EnsureExist()
    {
        if (!Directory.Exists(ConfigDirectory)) Directory.CreateDirectory(ConfigDirectory);
        if (!Directory.Exists(RootDirectory)) Directory.CreateDirectory(RootDirectory);
        if (!Directory.Exists(DatabaseDirectory)) Directory.CreateDirectory(DatabaseDirectory);
        if (!Directory.Exists(FtpDirectory)) Directory.CreateDirectory(FtpDirectory);
    }

    public Path(Config config)
    {
        _config = config;
        EnsureExist();
    }
}